<?php
/**
 * Copyright (c) 2010, http://alvaroveliz.cl
 * 
 * Permission is hereby granted, free of charge, to any
 * person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the
 * Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the
 * Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice
 * shall be included in all copies or substantial portions of
 * the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
 * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 * Facebook App client
 * @author @alvaroveliz
 **/
// Including configuration files
include('config/app.php');
include('config/facebook.php');

// Facebook connection
require_once('includes/connect.php');

// Including modules
foreach ($modules as $module) {
	include('modules/'. $module . '.php');
}

// Custom views
if (isset($_GET["section"])) {
	$view = $_GET["section"];
	if (file_exists('views/'.$view.'.php')) {
		ob_start();
		include("views/$view.php");
		$custom = ob_get_clean();
		echo $custom;
	}
	else {
		echo '<fb:fbml version="1.0">ERROR in view default.php</fb:fbml>';
	}
}
else {
	// Default view
	if (file_exists('views/default.php')) {
		ob_start();
		include("views/default.php");
		$default = ob_get_clean();
		echo $default;
	}
	else {
		echo '<fb:fbml version="1.0">ERROR in view default.php</fb:fbml>';
	}
}

// Profile views
if (file_exists('views/profile.php')) {
  ob_start();
  include("views/profile.php");
  $profile = ob_get_clean();

  ob_start();
  include("views/global.php");
  $global = ob_get_clean();

	$facebook->api_client->profile_setFBML(NULL, $user, $global, NULL, NULL, $profile);
	$facebook->api_client->fbml_refreshRefUrl($app_callbackurl.'views/profile.php?handle='.$fb_handle);
	$facebook->api_client->fbml_refreshRefUrl($app_callbackurl.'views/global.php?handle='.$fb_handle);
}
else {
	echo 'ERROR in profile view';
}


?>
